﻿using System;
using System.ComponentModel.DataAnnotations;
using Demo.Models.Dto;

namespace Demo.Attribute.Validation
{
    [AttributeUsage(AttributeTargets.Class)]
    public class EmployeeValidationAttribute : ValidationAttribute
    {
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            var addDto = (EmployeeAddDto) validationContext.ObjectInstance;

            if (addDto.EmployeeNo == addDto.FirstName)
            {
                return new ValidationResult(ErrorMessage, new[] {nameof(EmployeeAddDto)});
            }


            return ValidationResult.Success;
        }
    }
}
